(function(){"use strict";BX.namespace("BX.Main");BX.Main.dropdown=function(t){this.id=null;this.dropdown=null;this.items=null;this.value=null;this.menuId=null;this.menu=null;this.menuItems=null;this.dataItems="items";this.dataValue="value";this.dataPseudo="pseudo";this.dropdownItemClass="main-dropdown-item";this.activeClass="main-dropdown-active";this.selectedClass="main-dropdown-item-selected";this.notSelectedClass="main-dropdown-item-not-selected";this.menuItemClass="menu-popup-item";this.init(t)};BX.Main.dropdown.prototype={init:function(t){this.id=t.id;this.dropdown=t;this.items=this.getItems();this.value=this.getValue();this.menuId=this.getMenuId();this.menu=this.createMenu();this.menu.popupWindow.show();this.adjustPosition();BX.bind(this.dropdown,"click",BX.delegate(this.showMenu,this))},getMenuId:function(){return this.id+"_menu"},getItems:function(){var result;try{var str=BX.data(this.dropdown,this.dataItems);result=eval(str)}catch(t){result=[]}return result},getValue:function(){return BX.data(this.dropdown,this.dataValue)},prepareMenuItems:function(){var t=this;var e,s;var n=this.getValue();function i(a){return a.map(function(a){e={};e["data-"+t.dataValue]=a.VALUE;e["data-"+t.dataPseudo]="PSEUDO"in a&&a.PSEUDO?"true":"false";s=BX.create("div",{children:[BX.create("span",{props:{className:t.dropdownItemClass},attrs:e,text:a.NAME})]});return{text:s.innerHTML,className:n===a.VALUE?t.selectedClass:t.notSelectedClass,delimiter:a.DELIMITER,items:"ITEMS"in a?i(a.ITEMS):null}})}return i(this.getItems())},createMenu:function(){var t=this;return BX.PopupMenu.create(this.getMenuId(),this.dropdown,this.prepareMenuItems(),{autoHide:true,offsetTop:-8,offsetLeft:40,maxHeight:208,angle:{position:"bottom",offset:0},events:{onPopupClose:BX.delegate(this._onCloseMenu,this),onPopupShow:function(){t._onShowMenu()}}})},showMenu:function(){this.menu=BX.PopupMenu.getMenuById(this.menuId);if(!this.menu){this.menu=this.createMenu();this.menu.popupWindow.show()}this.adjustPosition()},adjustPosition:function(){if(this.dropdown.dataset.popupPosition==="fixed"){var t=this.menu.popupWindow.popupContainer;t.style.setProperty("top","auto");t.style.setProperty("bottom","45px");t.style.setProperty("left","0px");this.dropdown.appendChild(t)}},getSubItem:function(t){return BX.Grid.Utils.getByClass(t,this.dropdownItemClass,true)},refresh:function(t){var e=this.getSubItem(t);var s=BX.data(e,this.dataValue);BX.firstChild(this.dropdown).innerText=e.innerText;this.dropdown.dataset[this.dataValue]=s},selectItem:function(t){var e=this;(this.menu.menuItems||[]).forEach(function(s){BX.removeClass(s.layout.item,e.selectedClass);if(t!==s.layout.item){BX.addClass(s.layout.item,e.notSelectedClass)}else{BX.removeClass(s.layout.item,e.notSelectedClass)}});BX.addClass(t,this.selectedClass)},getDataItemIndexByValue:function(t,e){var s;if(BX.type.isArray(t)){t.map(function(t,n){if(t.VALUE===e){s=n;return false}})}return false},getDataItemByValue:function(t){var e=this.getItems().filter(function(e){return e.VALUE===t});return e.length>0?e[0]:null},_onShowMenu:function(){var t=this;BX.addClass(this.dropdown,this.activeClass);(this.menu.menuItems||[]).forEach(function(e){BX.bind(e.layout.item,"click",BX.delegate(t._onItemClick,t))})},_onCloseMenu:function(){BX.removeClass(this.dropdown,this.activeClass);BX.PopupMenu.destroy(this.menuId)},_onItemClick:function(t){var e=this.getMenuItem(t.target);var s,n;var i=this.getSubItem(e);var a=BX.data(i,"pseudo");if(!(a==="true")){this.refresh(e);this.selectItem(e);this.menu.popupWindow.close();s=this.getValue();n=this.getDataItemByValue(s)}else{s=BX.data(i,"value");n=this.getDataItemByValue(s)}t.stopPropagation();BX.onCustomEvent(window,"Dropdown::change",[this.dropdown.id,t,e,n,s])},getMenuItem:function(t){var e=t;if(!BX.hasClass(e,this.menuItemClass)){e=BX.findParent(e,{class:this.menuItemClass})}return e}}})();
//# sourceMappingURL=dropdown.map.js